package com.pxd.ServeDemo3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public interface TranscriptService {
    void soft(List<Double> score);
}

@Service("asc")
class ASCTranscriptServiceImpl implements TranscriptService{

    @Override
    public void soft(List<Double> score) {
        Collections.sort(score);
    }
}

@Service("desc")
class DESCTranscriptServiceImpl implements TranscriptService{

    @Override
    public void soft(List<Double> score) {
        Collections.sort(score, new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                if (o1>o2) {
                    return -1;
                }
                if (o1<o2) {
                    return 1;
                }
                return 0;
            }
        });
    }
}

@RestController
class TranscriptController{
    @Autowired
    TranscriptService asc;

    @Autowired
    TranscriptService desc;

    @RequestMapping("asc")
    public  String asc(Double class1, Double class2,Double class3){
        List<Double> list = Arrays.asList(class1, class2, class3);
        asc.soft(list);
        StringBuffer sb=new StringBuffer();
        list.stream().forEach(e->sb.append(e+"\t"));
        return sb.toString();
    }
    @RequestMapping("desc")
    public  String desc(Double class1, Double class2,Double class3){
        List<Double> list = Arrays.asList(class1, class2, class3);
        desc.soft(list);
        StringBuffer sb=new StringBuffer();
        list.stream().forEach(e->sb.append(e+"\t"));
        return sb.toString();
    }
}
